/**
 * Created by uptain on 2017/8/31.
 */
const vm = new Vue({
    el: '#main',
    data: {
        view: {
            main: true,
            detail: false,
            canlender: false,

        },
        data: {
            orderlist: [],
            monthIncome: 0,
            historyIncome: 0,
            date: {
                year: 0,
                month: 0,
            },
            order: {
                title: '',
                oid: '',
                all_pay: '',
                service: '',
                income: '',
                date: '',
            },
            list: [],
            dayTotal: 0,
            deposit: '',
            endDate: '',
            liquidatedDamages: '',
            payPrice: '',
            refundTotal: '',
            amount: '',
        },
    },
    methods: {
        todetail() {
            if (this.view.main) {
                this.view.detail = true;
                this.view.main = false;
            }
            else {
                this.view.detail = false;
                this.view.main = true;
            }
        },
        detailorder(id) {
            this.todetail();
            reqLandlordOrderIncomeDetail(id);
        },
        close_can() {
            this.view.canlender = 0;
        },
        show_can() {
            this.view.canlender = 1;
        },
        chouse_month(id) {
            this.data.date.month = id;
            this.close_can();
            reqsettle(this.data.date.year, this.data.date.month);
        },
        addyear() {
            this.data.date.year += 1;
        },
        subyear() {
            this.data.date.year -= 1;
        },
    },
});

function created() {
    const date = new Date();
    this.data.date.year = date.getFullYear();
    this.data.date.month = date.getMonth() + 1;
    reqsettle(this.data.date.year, this.data.date.month);
}

function apiready() {
    created.apply(vm);
}

function back() {
    if (vm.view.detail) {
        vm.view.detail = false;
        vm.view.main = true;
    }
    else {
        fxj.closeWin();
    }
}

async function reqsettle(year, month) {
    const res = await ajax({
        url: 'home/userCenter/Settlement',
        data: {
            year: year,
            month: month,
        },
    });
    if (res.err === 0 && res.data) {
        vm.data.orderlist = res.data.currentIncomeList;
        vm.data.monthIncome = res.data.currentIncome;
    }
    else {
        vm.data.orderlist = [];
        vm.data.monthIncome = 0;
    }
    if (res.err !== 0) {
        toast(res.msg);
    }
}

async function reqLandlordOrderIncomeDetail(orderId) {
    const res = await ajax({
        url: 'home/userCenter/getLandlordOrderIncomeDetail',
        data: {
            orderId,
        },
    });
    vm.data.order.title = res.data.title;
    vm.data.order.oid = res.data.oid;
    vm.data.order.all_pay = res.data.amount;
    vm.data.order.service = res.data.commission;
    vm.data.order.income = res.data.orderRealIncome;
    vm.data.order.date = res.data.pay_date;
    vm.data.list = res.data.list;
}